import { ICurve } from '@amcax/base';
import { createStore } from 'zustand/vanilla';

type SketchStore = {
  curves: ICurve[];
  updateSketchCurves: (curves: ICurve[]) => void;
  deleteSketchCurves: (ids: string[]) => void;
  cleanSketchCurves: VoidFunction;
};

export const sketchStore = createStore<SketchStore>((set) => ({
  curves: [],
  updateSketchCurves: (res) =>
    set(() => ({
      curves: res,
    })),
  deleteSketchCurves: (res) =>
    set((state) => ({
      curves: state.curves.filter((item) => !res.includes(item.id)),
    })),
  cleanSketchCurves: () =>
    set(() => ({
      curves: [],
    })),
}));
